package rickyGame.game
{
	import ricky.game.Actor;
	import ricky.game.action.Act2D;
	import ricky.game.perception.Percept;
	import ricky.game.perception.PerceptFactory;
	
	import rickyGame.model.config.*;
	import rickyGame.game.graphic.FightGraphic;
	import rickyGame.game.property.FightPro;
	import rickyGame.game.property.Ai;	
	import rickyGame.game.property.Skill;
	import rickyGame.server.SpellController;
	import ricky.game.Actor2D;
	
	/**
	 * 战斗对象，可以攻击和被攻击的对象
	 */
	public class Fighter extends Actor2D
	{
		public function Fighter()
		{
			_ai=new  Ai(this);
			graphic=new FightGraphic(this);/// FightGraphic
			_fightPro=new FightPro(this);
			_skills=new Skill(this);
			_stateNames=new Array();
		}

		override public function set name(value:String):void
		{
			super.name=value;
			FightGraphic(graphic).infoTxt=value;
		}
		
		override public function set isDead(value:Boolean):void
		{
			_isDead = value;
			if(_isDead)
			{
				while(_stateNames.length>0)
				{
					var act:Act2D=_stateNames.shift();
					if(act)
						act.complete();
				}
				
			}
		}
		
		/**
		 * 战斗属性
		 */
		public function get fightPro():FightPro
		{
			return _fightPro;
		}
		
		public function get stateNames():Array
		{
			return _stateNames;
		}
		
		public function set stateNames(value:Array):void
		{
			_stateNames = value;
		}
		
		public function get skills():Skill
		{
			return _skills;
		}
		
		public function set skills(value:Skill):void
		{
			_skills = value;
		}
		
		public function get fightCon():SpellController
		{
			return _fightCon;
		}
		
		public function set fightCon(value:SpellController):void
		{
			_fightCon = value;
		}
		
		/**
		 * 角色大脑ai
		 */
		public function get ai():Ai
		{
			return _ai;
		}
		
		public function set ai(value:Ai):void
		{
			_ai = value;
		}
		
		/**
		 * 感知函数
		 */
		public function perception(type:String,par:Object=null):Act2D
		{
			if(_ai.percept.indexOf(type)>=0)
			{
			 	_ai.lastPercept=_ai.currPercept;
				var per:Percept=PerceptFactory.getPercept(type);
				var act:Act2D;
				if(per)
					act=Act2D(per.calculate(this,par));
//				if(act)
//					this.addAct(act);
				
				return act
			}
			
			return null;
		}
		
		override protected function playanimactbyname(act:String=null):void
		{
			if(_direction==-1)
				this.graphic.playScene(act);
			else
				this.graphic.playScene(act+"_"+int(_direction).toString());
		}
		
		//属性
		protected var _ai:Ai;//角色ai配置
		protected var _stateNames:Array;//安装的状态
		protected var _skills:Skill;//技能
		protected var _fightPro:FightPro;//战斗属性
		protected var _fightCon:SpellController;//战斗控制器
		/**
		 * 读取配置文件
		 * 装载数据
		 */
		public function load(uint:Object):void
		{
			_data=uint;
		}

	
	}
}